/**
 *
 * @file
 *              heap_kh.h
 *
 * @brief
 *              declaration of heap class
 *
 * @author
 *              khlamov
 */

 /*
 Bitmapped memory manager. Class heap_kh encapsulates allocator's functionality
 struct memblock contains formated blocks of memory for user's pointer. Type - linked list
 */

#ifndef __HEAP_kh_H__
#define __HEAP_kh_H__

#include "heap.h"
#include <list>
#include <utility> //for pair<>
#include <stdlib.h>

//for debug
#include <iostream>

using std::list;
using std::pair;

class heap_kh: public heap876 {
private:
	void* _heap;
	size_t alloc_size; //


	/* mem_list
	implements access to heap
	void* - block of memory
	size_t - size of block
	bool - defines if block is unused
	*/
	list<pair<void*, pair<size_t, bool>>> mem_list;

	void push_list(void* v, size_t s, bool b); //add memory record to list


public:
	heap_kh(size_t total, alloc_flags flag);
	~heap_kh();

	void* alloc( size_t sz, unsigned int tag = 0 );
	void free( void* ptr );
	void free_all( unsigned int tag );
	size_t get_occupancy() const;


	//debug function. prints information about content of mem_list
	void prt();

};


#endif
